package com.tungse.juc;

import java.util.concurrent.TimeUnit;

/**
 * @author Tungse
 * 关于锁的8个问题
 * 1.公平锁和非公平锁
 * 2.可重入锁
 * 3.自旋锁
 * 4.读写锁
 * 5.互斥锁
 * 6.悲观锁
 * 7.乐观锁
 * 8.死锁
 */
public class LockTest {


    public static void main(String[] args) {
        Phone phone = new Phone();
        new Thread(phone::sendSms, "A").start();

        try {
        TimeUnit.SECONDS.sleep(1);
        } catch (Exception e) {
            e.printStackTrace();
        }

        new Thread(phone::call, "B").start();
    }


}

class Phone {

    public synchronized void sendSms() {
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("sendSms");
    }

    public synchronized void call() {
        System.out.println("call");
    }
}
